#ifndef ACTION_H
#define ACTION_H

#include <QStringList>
#include <QDomElement>
#include <QDomDocument>
#include "CommonMarcro.h"

class Action
{
public:
    Action();
    ~Action();

    inline void setName(const QString& name){m_name = name;}
    inline const QString& getName(){return m_name;}

    inline QStringList& getPlistName(){return m_plistFileName;}
    inline QStringList& getPlistPngName(){return m_plistPngName;}

    inline int getFrameCount(){return m_frameList.count();}

    inline void setDelay(float delay){m_delay = delay;}
    inline const float getDelay(){return m_delay;}


    void appendFrameList(const PlistFrameInfoList& frameNameList);
    void removeFrameByIndex(int index);
    QString getFrameNameByIndex(int index);
    bool setCurrentFrameByIndex(int index);

    inline PlistFrameInfo* getCurrentFrame(){return m_currentFrame;}
    inline int getCurrentFrameIndex(){if(m_currentFrame == NULL) return -1; return m_frameList.indexOf(m_currentFrame);}

    void convertFramenToDom(QDomElement &parent, QDomDocument* doc);
    void loadFromDom(const QDomElement& parentElement);

    void appendPlistInfo(PlistFrameInfoList infoList);


private:
    bool isValidIndex(int index);
    void convertRectToString(QRectF& rect, QDomElement& element,QString attributeName);
    void convertPointToString(QPointF& point, QDomElement& element,QString attributeName);
    void convertStringToRect(QRectF& rect, QDomElement& element,QString attributeName);
    void convertStringToPoint(QPointF& point, QDomElement& element,QString attributeName);
private:
   QString m_name;
   int m_frameNum;
   float m_delay;

   PlistFrameInfoList m_frameList;
   PlistFrameInfo* m_currentFrame;

   QStringList m_plistFileName;
   QStringList m_plistPngName;




private:
    static const QString DEFUAL_ACTION_NAME;

};

#endif // ACTION_H
